<script setup>
import { ref, watch } from 'vue';
import { useRoute, useRouter } from 'vue-router';

const router = useRouter();
const route = useRoute();
const selectedKeys = ref(['entity']);

watch(route, (newRoute) => {
  const matchedItem = menuItems.find(item => item.path === newRoute.path);
  if (matchedItem) {
    selectedKeys.value = [matchedItem.key];
  }
});

const menuItems = [
  {
    key: 'entity',
    label: '生成模块',
    path: '/'
  },
  {
    key: 'module',
    label: '生成实体',
    path: '/module'
  },
  {
    key: 'mysql',
    label: 'Mysql数据库',
    path: '/mysql'
  },
  {
    key: 'tool',
    label: '工具',
    path: '/tool'
  }
];

const handleMenuClick = ({ key }) => {
  const item = menuItems.find(i => i.key === key);
  if (item) {
    router.push(item.path);
  }
};
</script>

<template>
  <a-layout class="app-layout">
    <a-layout-header class="header">
      <div class="logo">AI Coding</div>
      <a-menu
        v-model:selectedKeys="selectedKeys"
        theme="dark"
        mode="horizontal"
        class="menu"
        @select="handleMenuClick"
      >
        <a-menu-item v-for="item in menuItems" :key="item.key">
          {{ item.label }}
        </a-menu-item>
      </a-menu>
    </a-layout-header>
    <a-layout-content class="main-content">
      <div class="content-wrapper">
        <router-view></router-view>
      </div>
    </a-layout-content>
    <a-layout-footer class="footer">
      AI Coding ©2024 Created by Your Team
    </a-layout-footer>
  </a-layout>
</template>

<style>
/* 重置基础样式 */
html, body {
  margin: 0;
  padding: 0;
  background: #f5f5f5;
}

.app-layout {
  min-height: 100vh;
  min-width: 100vw;
}

/* 头部样式 */
.header {
  display: flex;
  align-items: center;
  padding: 0 50px;
  background: #001529;
  position: fixed;
  width: 100%;
  z-index: 1000;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.logo {
  color: #fff;
  font-size: 20px;
  font-weight: 600;
  margin-right: 48px;
  font-family: 'Arial', sans-serif;
}

.menu {
  flex: 1;
  background: transparent;
  border-bottom: none;
}

/* 主内容区域 */
.main-content {
  padding: 88px 50px 24px;
  min-height: calc(100vh - 134px);
  background: #f5f5f5;
}

.content-wrapper {
  max-width: 1200px;
  margin: 0 auto;
  background: transparent;
}

/* 页脚 */
.footer {
  text-align: center;
  background: #f0f2f5;
  padding: 24px 50px;
  color: rgba(0, 0, 0, 0.45);
}

/* Ant Design 组件样式覆盖 */
:deep(.ant-layout-header) {
  height: 64px;
  line-height: 64px;
}

:deep(.ant-menu-horizontal) {
  line-height: 62px;
}

:deep(.ant-menu-item) {
  padding: 0 20px;
  font-size: 14px;
  transition: all 0.3s ease;
}

:deep(.ant-menu-item:hover) {
  background: rgba(255, 255, 255, 0.1);
}

:deep(.ant-menu-item-selected) {
  font-weight: 500;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .header {
    padding: 0 20px;
  }

  .main-content {
    padding: 88px 20px 24px;
  }

  .footer {
    padding: 24px 20px;
  }

  .logo {
    margin-right: 24px;
  }
}
</style>
